import os
import re

def find_user_logs(directory):
    """查找符合条件(dengji 95-105, nicelvel=6, jingyan=10751)的用户日志"""
    pattern = re.compile(
        r'User\(.*?userid=(0x[0-9a-fA-F]+).*?nicelvel=6.*?dengji=(\d+).*?jingyan=10751',
        re.DOTALL
    )

    results = []

    for root, _, files in os.walk(directory):
        for filename in files:
            if not filename.endswith('.log'):  # 假设日志文件以.log结尾，根据需要修改
                continue

            filepath = os.path.join(root, filename)
            try:
                with open(filepath, 'r', encoding='utf-8') as f:
                    content = f.read()

                for match in pattern.finditer(content):
                    userid = match.group(1)
                    dengji = int(match.group(2))

                    if 95 <= dengji <= 105:
                        results.append((filename, userid))

            except Exception as e:
                print(f"处理文件 {filename} 时出错: {e}")

    return results

if __name__ == "__main__":
    log_directory = input("C:/Users/ma/Desktop/log").strip()

    if not os.path.isdir(log_directory):
        print("错误: 提供的路径不是有效的目录")
    else:
        matches = find_user_logs(log_directory)

        if matches:
            print("\n找到匹配的日志条目:")
            for filename, userid in matches:
                print(f"文件: {filename} - UserID: {userid}")
        else:
            print("没有找到符合条件(dengji 95-105, nicelvel=6, jingyan=10751)的日志条目")